[eventloop] Fix main loop keepalive cleanup when cancelling or pausing - #27468
Open
sbc100 wants to merge 1 commit into
Open
[eventloop] Fix main loop keepalive cleanup when cancelling or pausing#27468sbc100 wants to merge 1 commit into
sbc100 wants to merge 1 commit into
Conversation
sbc100
force-pushed
the
fix-mainloop-shutdown-27456
branch
2 times, most recently
from
July 31, 2026 19:55
87aeae8 to
139020e
Compare
Pop runtimeKeepaliveCounter immediately in MainLoop.pause() when a main loop is paused or cancelled, rather than deferring the pop until checkIsRunning() runs at the end of the next frame tick. This fixes cases where exit() or emscripten_force_exit() is called immediately after emscripten_cancel_main_loop() from within the main loop callback. Additionally, remove the redundant MainLoop.running property, using MainLoop.scheduler directly to determine if a main loop is active. Fixes: emscripten-core#27456
sbc100
force-pushed
the
fix-mainloop-shutdown-27456
branch
from
July 31, 2026 19:59
139020e to
c02b9c2
Compare
kripken
reviewed
Aug 3, 2026
| // This will be non-null whenever a loop function is registered. | ||
| func: null, | ||
| // This will be non-null whenever a loop function is both registered and | ||
| // currently running. |
Member
There was a problem hiding this comment.
What is the difference between "registered" and "registered and currently running"?
Collaborator
Author
There was a problem hiding this comment.
Registered meas somebody called emscripten_set_main_loop.
Running can be false if somebody calls emscripten_pause_main_loop, but even while pauses the callback is still "registered", because one can call emscripten_resume_main_loop to re-use the same callback.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pop
runtimeKeepaliveCounterimmediately inMainLoop.pause()when a main loop is paused or cancelled, rather than deferring the pop untilcheckIsRunning()runs at the end of the next frame tick.This fixes cases where
exit()oremscripten_force_exit()is called immediately afteremscripten_cancel_main_loop()from within the main loop callback.Additionally, remove the redundant
MainLoop.runningproperty, using MainLoop.scheduler directly to determine if a main loop is active.Fixes: #27456